package com.ruoyi.web.controller;

import com.ruoyi.business.UserCategory;
import com.ruoyi.business.service.UserCategoryService;
import com.ruoyi.common.common.ResultBody;
import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @title: CustomerController
 * @copyright: copyright (c) 2021
 * @author: jiangguanjun
 * @date: 2023/1/29 14:56
 * @firstReview:
 * @lastReview:
 * @desc: 用户类目管理
 */
@Api(value = "UserCategoryController", tags = "用户类目管理")
@RestController
@Slf4j
@RequestMapping("/userCategory")
public class UserCategoryController {
    private static final Integer VISIT_OUT_TIME = 24;
    @Autowired
    private UserCategoryService userCategoryService;

    @Autowired
    private RedisTemplate redisTemplate;


    @Value("${city.path}")
    private String path  ;



    @CrossOrigin
    @GetMapping("/listAll")
    @ApiOperation(value = "获取当前用户类目")
    public ResultBody listAll( ){
        Long userId = SecurityUtils.getUserId() ;
        log.info("userId：{}",userId);
        return userCategoryService.listAll(userId) ;
    }

    @CrossOrigin
    @PostMapping("/add")
    @ApiOperation(value = "当前用户添加关注的类目 只需要穿cId字段")
    public ResultBody add(@RequestBody UserCategory userCategory){
        Long userId = SecurityUtils.getUserId() ;
        log.info("userId：{}",userId);
        return userCategoryService.add(userId,userCategory.getcId()) ;
    }

    @CrossOrigin
    @DeleteMapping("/delete")
    @ApiOperation(value = "当前用户删除某一类目 ")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户关注关系类目id", dataType = "Integer"),
    })
    public ResultBody add(@RequestParam(value = "id") Integer id){
        Long userId = SecurityUtils.getUserId() ;
        log.info("userId：{}",userId);
        return userCategoryService.delete(id) ;
    }



}
